<?php
/**------------------------------------------------------------------------
 * @Author:      lixw
 * @DateTime:    2017-01-10 22:33:06
 * @Description: Description
 * Copyright (c) 2016 All rights reserved.
 *------------------------------------------------------------------------*/
namespace app\wap\controller;

class Category extends Base{
	/**
	 * 选择类别插件
	 * @param  string  $show_name       显示名称
	 * @param  string  $field_name      字段名称
	 * @param  string  $field_value     字段值
	 * @param  string  $category_module 类别模块
	 * @param  string  $show_desc       显示描述
	 * @param  integer $is_wrap_name    是否包含HTML
	 * @param  integer $is_tree         是否树形结构
	 */
    public function index(){
   
		$show_name       = $this->_get('show_name');
		$field_name      = $this->_get('field_name', '', 'category_id');
		$field_value     = $this->_get('field_value');
		$category_module = $this->_get('category_module');
		$show_desc       = $this->_get('show_desc');
		$is_required     = $this->_get('is_required', '', 0);
		$is_wrap_name    = $this->_get('is_wrap_name', '', 1);
		$is_tree         = $this->_get('is_tree', '', 0);

		$field_name   = $field_name ? $field_name : 'category_id';//字段
		$show_name    =  $show_name ? urldecode($show_name) : '类别';//显示名称
		$show_desc    = $show_desc ? '(' . urldecode($show_desc) . ')' : '';
		$is_wrap_name = $is_wrap_name == 1 ? 1 : 0;
		$is_tree      = $is_tree == 1 ? 1 : 0;
		$is_required  = $is_required == 1 ? 1 : 0;

		$where['module'] = $category_module;
		$where['status'] = 1;
		$category_list = model('Category')->where($where)->order('order_id,category_id desc')->select();
    	
    	if($is_tree){
			import('Tree', EXTEND_PATH, '.class.php');
			$tree = new \Tree($category_list, 'category_id', 'parent_id');
			$category_list = $tree->getTrees();
			foreach ($category_list as $rs) {
				$rs['title'] = $rs['prefix_title'];
				$new_list[] = $rs;
			}
			$category_list = $new_list;
		}

		$this->assign('show_name', $show_name);
		$this->assign('show_desc', $show_desc);
		$this->assign('is_wrap_name', $is_wrap_name);
		$this->assign('field_name', $field_name);
		$this->assign('field_value', $field_value);
		$this->assign('is_required', $is_required);
		$this->assign('_category_list', $category_list);

		return $this->view();
    }
}